<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
class Common extends Controller
{
	//保存管理员数据的变量
	public $info = array();

	public function __construct()
    {
    	parent::__construct();
    	$this->checkLogin();
		$this->nav_constant();

		//检查是否有未读充值凭证信息
		$certificate_count =db('certificate')->where(['is_reading'=>'0'])->count();

		define('MODULE_NAME',$this->request->module());  // 当前模块名称是
		define('CONTROLLER_NAME',$this->request->controller()); // 当前控制器名称
		define('ACTION_NAME',$this->request->action()); // 当前操作名称是
		$this->assign("certificate_count",$certificate_count);
    }

    //判断是否已经登陆
	private function checkLogin()
	{
		$this->info = session("info");
		
		if(!$this->info){
			$this->redirect("Login/login");
		}else{
			$this->assign("info",$this->info);
		}
	}
	
	//pc导航
	private function nav_constant()
	{
		$admin_nav = db('admin_nav')->select();

		$this->assign('Home',$admin_nav[0]['name']);
		$this->assign('Loan',$admin_nav[1]['name']);
		$this->assign('Consultant',$admin_nav[2]['name']);
		$this->assign('LoanHelp',$admin_nav[3]['name']);
		$this->assign('About',$admin_nav[4]['name']);

		$home = db('article_category')->where('nav_id=1 and pid=0')->select();
		$this->assign('homelist', $home);

		$loan = db('article_category')->where('nav_id=2 and pid=0')->select();
		$this->assign('loanlist', $loan);

		$about = db('article_category')->where('nav_id=5 and pid=0')->paginate()->each(function($item, $key){
			$item['chlid']=[];
			$chlid = db('article_category')->where(['pid'=>$item['id']])->select();
			if($chlid){
				$item['chlid']=$chlid;
			}
			return $item;
		});
//		halt($about);
		$this->assign('aboutlist', $about);
	}
}